<%-- 
    Document   : vieworder
    Created on : Sep 20, 2011, 10:31:18 AM
    Author     : Quangtv
--%>

<%@page import="Assignment.BLO.OrderBLO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.net.URL"%>
<%@page import="Assignment.BLO.BookBLO"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.Properties"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Admin's Page</title>
        <link href="css/style.css" rel="stylesheet" type="text/css"/>
        <link href="css/bannerstyle.css" rel="stylesheet" type="text/css"/>
        <link href="css/TableCSS.css" rel="stylesheet" type="text/css"/>

        <link href="css/thumbnail_css.css" rel="stylesheet" type="text/css"/>

        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

        <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
        <%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
        <script type="text/javascript">
            function setVisibility(showUser, isAdmin){
                if(showUser == "true"){
                    document.getElementById("user").style.visibility = "visible";
                    document.getElementById("loggeduser").style.visibility = "hidden";
                }else if(showUser == "false" && isAdmin == "true"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| Admin";
                    document.getElementById("user_link").href = "admin.jsp";
                }else if(showUser == "false" && isAdmin == "false"){
                    document.getElementById("loggeduser").style.visibility = "visible";
                    document.getElementById("user").style.visibility = "hidden";
                    document.getElementById("user_link").textContent = "| View Cart";
                    document.getElementById("user_link").href = "viewcart.jsp";
                }
            }

            function checkRemove() {
                var result = false;
                var list =  document.getElementsByName("cBox");
                for (i=0; i<list.length; i++) {
                    if (list[i].checked) {
                        return true;
                    } else {
                        result = false;
                    }
                }
                return result;
            }
        </script>
        <%
                    String loggedUser = (String) session.getAttribute("USER");
                    String showUser = "";
                    String isAdmin = "";
                    if (loggedUser == null) {
                        showUser = "true";
                    } else {
                        showUser = "false";
                        isAdmin = (String) session.getAttribute("ISADMIN");
                        if (isAdmin == null || isAdmin == "false") {
                            isAdmin = "false";
                        } else {
                            isAdmin = "true";
                        }
                    }
                    OrderBLO oBLO = new OrderBLO();
                    String path = oBLO.getAllOrders();
                    URL url = (new File(path)).toURI().toURL();
                    String docURL = url.toString();
                    session.setAttribute("ORDERURL", docURL);
        %>
    </head>
    <body onload='setVisibility("<%=showUser%>","<%=isAdmin%>")'>
        <%
                    String strCatSearch = (String) request.getAttribute("CATEGORY");
                    //String attCatSearch = (String) request.getParameter("CATEGORY");
                    boolean isCatSearch = false;
                    //if ((strCatSearch == null && attCatSearch =="false") || (strCatSearch == "false" && attCatSearch == null)) {
                    if (strCatSearch == null || strCatSearch == "false") {
                        isCatSearch = false;
                    } else {
                        isCatSearch = true;
                    }
        %>
        <div id="header-wrap">
            <div id="header">
                <div style="margin:0px; text-align: left; float: left;"> <span style="color: #FFFFFF; font-family:'Arial Black',Gadget,sans-serif; font-size: 20px; font-weight: bold; letter-spacing: -2px;"><a href="index.jsp" style="color: #FFF; text-decoration: none;" title="Awesomebooks.com">AWESOMEBOOKS</a></span> <a style="color: #FFF; font-size: 18px; font-family: Georgia, 'Times New Roman', Times, serif; font-style:italic; font-weight:normal; text-decoration: none;" href="index.jsp" title="Find your own book">Find your own book</a> 	</div>
                <ul class="menu">

                    <!-- Begin Simple Item Without Drop -->
                    <li class="">
                        <a href="newrelease.jsp">New Release</a>
                    </li>
                    <li class="">
                        <a href="bestseller.jsp">Best Seller</a>
                    </li>
                    <li class="">
                        <a href="bookreview.jsp">Books Review</a>
                    </li>

                    <li class="drop">
                        <a href="#">Catalogs</a>
                        <span class="toggle">&nbsp;</span>
                        <ul>
                            <li><a href="Controller?Action=Search&searchText=literature&Category=true">Literature</a></li>
                            <li><a href="Controller?Action=Search&searchText=life style&Category=true">Life Style</a></li>
                            <li><a href="Controller?Action=Search&searchText=tutorial&Category=true">Tutorial</a></li>
                            <li><a href="Controller?Action=Search&searchText=discovery&Category=true">Discovery</a></li>
                            <li><a href="Controller?Action=Search&searchText=science&Category=true">Science</a></li>
                            <li><a href="Controller?Action=Search&searchText=kids&Category=true">Kids</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div id="underheader">
                <form action="Controller">
                    <span id="searchbox" style="width:50%">
                        <input name="searchText" type="text" style="width:250px; border:1px solid #333333" />
                        <input name="Action" type="submit" value="Search" id="button" />
                    </span>
                    <span id="user" style="width:50%">
                        <a href="login.jsp">Login</a> |
                        <a href="register.jsp">Register</a>
                    </span>
                    <span id="loggeduser" style="width:50%;position: relative; left: -180px; visibility: hidden">
                        <a><%=loggedUser%></a>
                        <a href="Controller?Action=Logout">(Logout)</a>
                        <a href="viewcart.jsp" id="user_link">| View Cart</a>
                    </span>
                </form>
            </div>
        </div>
        <center>
            <div id="content-header" style="height: 50px">
                <ul>
                    <a>Manage orders</a>
                </ul>
            </div>

            <c:import var="docURL" url="<%=docURL%>" />
            <x:parse var="doc" xml="${docURL}" />

            <form action="Controller" id="content" style="position: relative; left: 0px">
                <br/>
                <input type="submit" value="Delete order" id="button" name="Action" style="float: right; position: relative; right: 10px"
                       onclick="return checkRemove();"/>
                <br/>
                <table style="width: 98%" >
                    <thead style="height: 40px;background-color: #333333; color: white">
                        <tr>
                            <th  style="width: 5%">No.</th>
                            <th  style="width: 20%">Name</th>
                            <th  style="width: 20%">Date</th>
                            <th  style="width: 20%">Delivery Date</th>
                            <th  style="width: 15%">Price</th>
                            <th  style="width: 10%">Status</th>
                            <th  style="width: 10%">Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:set var="count" value="1" />
                        <x:forEach var="order" select="$doc//Order">
                            <tr style="background-color: #C0C0C0; color: #666666">
                                <td style="height: 50px; width: 5%">
                                    <a href="orderdetail.jsp?orderID=<x:out select="orderID" />"><c:out value="${count}" /></a></td>
                                <td style="height: 50px; width: 30%"><x:out select="username" /></td>
                                <td style="height: 50px; width: 20%"><x:out select="orderDate" /></td>
                                <td style="height: 50px; width: 20%"><x:out select="deliveryDate" /></td>
                                <td style="height: 50px; width: 15%"><x:out select="totalPrice" /></td>
                                <td style="height: 50px; width: 10%"><x:out select="status" /></td>
                                <td style="height: 50px; width: 10%"><input name="cBox" type="checkbox" value="<x:out select="orderID" />" /></td>
                            </tr>
                            <c:set var="count" value="${count+1}" />
                        </x:forEach>
                        <tr style="background-color: #333333">
                            <td colspan="7" style="height: 20px">|< < > >|</td>
                        </tr>
                    </tbody>
                </table>

            </form>
        </center>
    </body>
</html>
